using Microsoft.AspNetCore.Mvc;
using CollabApp.Domain.Services.Users;

namespace CollabApp.API.Controllers;

[ApiController]
[Route("api/[controller]")]
public class UserController : ControllerBase
{
    private readonly IUserService _userService;
    public UserController(IUserService userService)
    {
        _userService = userService;
    }

    public class UpdateAvatarDto
    {
        public Guid UserId { get; set; }
        public string Avatar { get; set; } = string.Empty;
    }

    // 个人中心概览
    [HttpGet("overview/{userId}")]
    public async Task<IActionResult> GetOverview(Guid userId)
    {
        var result = await _userService.GetPersonalOverviewAsync(userId);
        return Ok(result);
    }

    // 修改头像
    [HttpPost("avatar/update")]
    public async Task<IActionResult> UpdateAvatar([FromBody] UpdateAvatarDto dto)
    {
        var result = await _userService.UpdateAvatarAsync(dto.UserId, dto.Avatar);
        return Ok(result);
    }

    public class ChangePasswordDto
    {
        public Guid UserId { get; set; }
        public string CurrentPassword { get; set; } = string.Empty;
        public string NewPassword { get; set; } = string.Empty;
        public string ConfirmNewPassword { get; set; } = string.Empty;
    }

    // 修改密码（安全设置）
    [HttpPost("change-password")]
    public async Task<IActionResult> ChangePassword([FromBody] ChangePasswordDto dto)
    {
        var result = await _userService.ChangePasswordAsync(dto.UserId, dto.CurrentPassword, dto.NewPassword, dto.ConfirmNewPassword);
        return Ok(result);
    }
}   